package com.shqcjd.siemensglass.http;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

/**
 * Created by sy on 2018/5/3.
 */

public class OkHttpUtils {
    private final static long HTTP_CONNECT_TIMEOUT = 10;
    private final static long HTTP_READ_TIMEOUT = 30;
    private static OkHttpClient singleton;
    public static OkHttpClient getInstance() {
        if (singleton == null) {
            synchronized (OkHttpClient.class) {
                if (singleton == null) {
                    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(new HttpLogger());
                    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
                    OkHttpClient.Builder builder = new OkHttpClient.Builder();
                    builder.connectTimeout(HTTP_CONNECT_TIMEOUT, TimeUnit.SECONDS)
                            .readTimeout(HTTP_READ_TIMEOUT, TimeUnit.SECONDS)
                            .addInterceptor(interceptor);
                    singleton = builder.build();


                }
            }
        }
        return singleton;
    }


}
